<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
// Soft line break after white space
const kStyle = 'line-break:after-white-space; width:100px; font: 20px monospace;';
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">|line1 line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">^line1| line2 a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">^line1 |line2 a line3</div>`,
  `${behavior} 22-0 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">l|ine1 line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">l^ine1| line2 a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">l^ine1 |line2 a line3</div>`,
  `${behavior} 22-1 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">li|ne1 line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">li^ne1| line2 a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">li^ne1 |line2 a line3</div>`,
  `${behavior} 22-2 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">lin|e1 line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">lin^e1| line2 a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">lin^e1 |line2 a line3</div>`,
  `${behavior} 22-3 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line|1 line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line^1| line2 a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line^1 |line2 a line3</div>`,
  `${behavior} 22-4 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1| line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1^ line2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1^ |line2 a line3</div>`,
  `${behavior} 22-5 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 |line2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 ^line2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 ^line2 |a line3</div>`,
  `${behavior} 22-6 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 l|ine2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 l^ine2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 l^ine2 |a line3</div>`,
  `${behavior} 22-7 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 li|ne2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 li^ne2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 li^ne2 |a line3</div>`,
  `${behavior} 22-8 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 lin|e2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 lin^e2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 lin^e2 |a line3</div>`,
  `${behavior} 22-9 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line|2 a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line^2| a line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line^2 |a line3</div>`,
  `${behavior} 22-10 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2| a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2^ a| line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2^ |a line3</div>`,
  `${behavior} 22-11 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 |a line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 ^a| line3</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 ^a |line3</div>`,
  `${behavior} 22-12 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a| line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  behavior === 'mac'
      ? `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a^ line3|</div>`
      : `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a^ |line3</div>`,
  `${behavior} 22-13 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a |line3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a ^line3|</div>`,
  `${behavior} 22-14 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a l|ine3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a l^ine3|</div>`,
  `${behavior} 22-15 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a li|ne3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a li^ne3|</div>`,
  `${behavior} 22-16 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a lin|e3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a lin^e3|</div>`,
  `${behavior} 22-17 ltr forward word`);

selection_test(
  `<div contenteditable dir="ltr" style="${kStyle}">line1 line2 a line|3</div>`,
  selection => selection.modify('extend', 'forward', 'word'),
  `<div contenteditable dir="ltr" style="line-break:after-white-space; width:100px; font: 20px monospace;">line1 line2 a line^3|</div>`,
  `${behavior} 22-18 ltr forward word`);
}
</script>
